package com.corpgovernment.common.apollo;

import com.alibaba.fastjson.JSONObject;
import com.ctrip.corp.obt.generic.core.context.TenantContext;
import com.ctrip.corp.obt.generic.utils.JsonUtils;
import lombok.Getter;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;

import java.util.List;
import java.util.Map;

/**
 * @ClassName: PayPlatformApollo
 * @description: 支付平台阿波罗配置
 * @author: ezchen
 * @date: Created in 13:59 2020/7/8
 * @Version: 1.0
 **/
@Component
@Getter
public class PayPlatformApollo extends CommonApollo {

    /**
     * 供应商支付信息配置
     */
    @Value("${supplier_pay_config:''}")
    private String supplierPayConfig;
    /**
     * 支付宝网关
     */
    @Value("${GATEWAY_URL:https://openapi.alipay.com/gateway.do}")
    private String gatewayUrl;
    /**
     * 支付宝后台通知url
     */
    @Value("${ALIPAY_NOTIFY_URL:1.0}")
    private String alipayNotifyUrl;
    /**
     * 微信下单url
     */
    @Value("${UNIFIED_ORDER_URL:https://api.mch.weixin.qq.com/pay/unifiedorder}")
    private String unifiedOrderUrl;
    /**
     * 微信查询订单url
     */
    @Value("${CHECK_ORDER_URL:https://api.mch.weixin.qq.com/pay/orderquery}")
    private String checkOrderUrl;
    /**
     * 微信后台通知url
     */
    @Value("${WECHAT_NOTIFY_URL:https://b2c.ispacechina.com/corpApi/payGateway/payNotify/wechatPay}")
    private String wechatNotifyUrl;
    /**
     * 微信后台退款成功通知url
     */
    @Value("${WECHAT_REFUND_NOTIFY_URL:https://b2c.ispacechina.com/corpApi/payGateway/payNotify/wechatRefundSuccessNotify}")
    private String wechatRefundNotifyUrl;
    /**
     * 微信退款url
     */
    @Value("${REFUND_URL:https://api.mch.weixin.qq.com/secapi/pay/refund}")
    private String refundUrl;
    /**
     * PC支付完成机票订单跳转页面
     */
    @Value("${PC_PAY_FLIGHT_DETAIL_URL:}")
    private String pcPayFlightDetailUrl;
    /**
     * PC支付完成国际机票订单跳转页面
     */
    @Value("${PC_PAY_INTLFLIGHT_DETAIL_URL:}")
    private String pcPayIntlflightDetailUrl;
    /**
     * PC支付完成酒店订单跳转页面
     */
    @Value("${PC_PAY_HOTEL_DETAIL_URL:}")
    private String pcPayHotelDetailUrl;
    /**
     * PC支付完成火车票订单跳转页面
     */
    @Value("${PC_PAY_TRAIN_DETAIL_URL:}")
    private String pcPayTrainDetailUrl;
    /**
     * 微信退款认证证书路径
     */
    @Value("${payPath:/opt/corpgov/pay-platform-server/}")
    private String payPath;
    /**
     * 结算查询口令
     */
    @Value("${check_amount_key:}")
    private String checkAmountKey;
    /**
     * 结算查询服务商编码
     */
    @Value("${check_amount_supplier_code:}")
    private String checkAmountSupplierCode;
    /**
     * 机票结算明细地址
     */
    @Value("${check_amount_flight_url:}")
    private String checkAmountFlightUrl;
    /**
     * 酒店结算明细地址
     */
    @Value("${check_amount_hotel_url:}")
    private String checkAmountHotelUrl;
    /**
	 * 火车结算明细地址
	 */
	@Value("${check_amount_train_url:}")
	private String checkAmountTrainUrl;
	/**
	 * 用车结算明细地址
	 */
	@Value("${check_amount_car_url:}")
	private String checkAmountCarUrl;

	/**
	 * 支付成功跳转url
	 */
	@Value("${payReturnUrl:}")
	private String payReturnUrl;

	@Value("${CTRIP_PUBLIC_KEY:''}")
	private String ctripPublicKey;

	/**
	 * 携程创建bill单接口
	 */
	@Value("${TRIP_CREATE_BILL_URL:}")
	private String tripCreateBillUrl;

	/**
	 * 携程创建bill单接口
	 */
	@Value("${TRIP_QUERY_BILL_URL:}")
	private String tripQueryBillUrl;
	/**
	 * 携程创建bill单userKey
	 */
	@Value("${TRIP_CREATE_BILL_USER_KEY:'123456789'}")
	private String tripCreateBillUserKey;
	/**
	 * App站点的HOST地址
	 */
	@Value("${app.host:}")
	private String appHost;
	/**
	 * 单次创建发票的最大订单数量
	 */
	@Value("${create_invoice_count:100}")
	private Integer createInvoiceMaxCount;
	/**
	 * 单次查询发票的最大订单数量
	 */
	@Value("${query_invoice_count:100}")
	private Integer queryInvoiceMaxCount;
	/**
	 * 单次查询发票的最大订单数量
	 */
	@Value("${account_id_length:16}")
	private Integer accountIdLength;

	@Value("${app.path:}")
	private String appPath;

    /**
     * 国际机票走新流水入账的租户id,多个用|分隔,ALL表示全部
     */
    @Value("${enableNewIntlFlightTransactionTenantId:''}")
    private String enableNewIntlFlightTransactionTenantId;

	/**
	 * 供应商支付信息配置
	 */
	public String getSupplierPayConfig() {
		return getAppProperty("supplier_pay_config", null);
	}


	public Integer getQueryInvoiceMaxCount() {
		return Integer.parseInt(getAppProperty("query_invoice_count", "100"));
	}
	/**
	 * 支付宝网关
	 */
	public String getGatewayUrl(){
		return getAppProperty("GATEWAY_URL", "https://openapi.alipay.com/gateway.do");
	}

	/**
	 * 支付宝后台通知url
	 */
	public String getAlipayNotifyUrl(){
		return getAppProperty("ALIPAY_NOTIFY_URL", "1.0");
	}

	/**
	 * 微信下单url
	 */
	public String getUnifiedOrderUrl(){
		return getAppProperty("UNIFIED_ORDER_URL", "https://api.mch.weixin.qq.com/pay/unifiedorder");
	}

	/**
	 * 微信查询订单url
	 */
	public String getCheckOrderUrl(){
		return getAppProperty("CHECK_ORDER_URL", "https://api.mch.weixin.qq.com/pay/orderquery");
	}

	/**
	 * 微信后台通知url
	 */
	public String getWechatNotifyUrl(){
		return getAppProperty("WECHAT_NOTIFY_URL", "https://b2c.ispacechina.com/corpApi/payGateway/payNotify/wechatPay");
	}

	/**
	 * 微信后台退款成功通知url
	 */
	public String getWechatRefundNotifyUrl(){
		return getAppProperty("WECHAT_REFUND_NOTIFY_URL", "https://b2c.ispacechina.com/corpApi/payGateway/payNotify/wechatRefundSuccessNotify");
	}

	/**
	 * 微信退款url
	 */
	public String getRefundUrl(){
		return getAppProperty("REFUND_URL", "https://api.mch.weixin.qq.com/secapi/pay/refund");
	}

	/**
	 * PC支付完成机票订单跳转页面
	 */
	public String getPcPayFlightDetailUrl(){
		return getAppProperty("PC_PAY_FLIGHT_DETAIL_URL", "");
	}

	/**
	 * PC支付完成国际机票订单跳转页面
	 */
	public String getPcPayIntlflightDetailUrl(){
		return getAppProperty("PC_PAY_INTLFLIGHT_DETAIL_URL", "");
	}

	/**
	 * PC支付完成酒店订单跳转页面
	 */
	public String getPcPayHotelDetailUrl(){
		return getAppProperty("PC_PAY_HOTEL_DETAIL_URL", "");
	}

	/**
	 * PC支付完成火车票订单跳转页面
	 */
	public String getPcPayTrainDetailUrl(){
		return getAppProperty("PC_PAY_TRAIN_DETAIL_URL", "");
	}

	/**
	 * 微信退款认证证书路径
	 */
	public String getPayPath(){
		return getAppProperty("payPath", "/opt/corpgov/pay-platform-server/");
	}

	/**
	 * 结算查询口令
	 */
	public String getCheckAmountKey(){
		return getAppProperty("check_amount_key", "");
	}

	/**
	 * 结算查询服务商编码
	 */
	public String getCheckAmountSupplierCode(){
		return getAppProperty("check_amount_supplier_code", "");
	}

	/**
	 * 机票结算明细地址
	 */
	public String getCheckAmountFlightUrl(){
		return getAppProperty("check_amount_flight_url", "");
	}

	/**
	 * 酒店结算明细地址
	 */
	public String getCheckAmountHotelUrl(){
		return getAppProperty("check_amount_hotel_url", "");
	}

	/**
	 * 火车结算明细地址
	 */
	public String getCheckAmountTrainUrl(){
		return getAppProperty("check_amount_train_url", "");
	}

	/**
	 * 用车结算明细地址
	 */
	public String getCheckAmountCarUrl(){
		return getAppProperty("check_amount_car_url", "");
	}

	/**
	 * 支付成功跳转url
	 */
	public String getPayReturnUrl(){
		return getAppProperty("payReturnUrl", "");
	}


	public String getCtripPublicKey(){
		return getAppProperty("CTRIP_PUBLIC_KEY", "");
	}

	/**
	 * 携程创建bill单接口
	 */
	public String getTripCreateBillUrl(){
		return getAppProperty("TRIP_CREATE_BILL_URL", "");
	}

	/**
	 * 携程创建bill单接口
	 */
	public String getTripQueryBillUrl(){
		return getAppProperty("TRIP_QUERY_BILL_URL", "");
	}

	/**
	 * 携程创建bill单userKey
	 */
	public String getTripCreateBillUserKey(){
		return getAppProperty("TRIP_CREATE_BILL_USER_KEY", "123456789");
	}

	/**
	 * App站点的HOST地址
	 */
	public String getAppHost(){
		return getAppProperty("app.host", "");
	}

	/**
	 * 单次创建发票的最大订单数量
	 */
	public Integer getCreateInvoiceMaxCount(){
		return Integer.parseInt(getAppProperty("create_invoice_count", "100"));
	}

	/**
	 * 单次查询发票的最大订单数量
	 */
	public Integer queryInvoiceMaxCount(){
		return Integer.parseInt(getAppProperty("query_invoice_count", "100"));
	}

	/**
	 * 单次查询发票的最大订单数量
	 */
	public Integer getAccountIdLength(){
		return Integer.parseInt(getAppProperty("account_id_length", "16"));
	}
	public String getAppPath() {
		return getAppProperty("app.path", "");
	}

	/**
	 * 国际机票走新流水入账
	 */
	public boolean enableNewIntlFlightTransaction() {
		return existsItemOrAll("enableNewIntlFlightTransactionTenantId", TenantContext.getTenantId());
	}
}
